home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / uw_1.exe / STR_DEMO.C < prev    next >
Text File  |  1992-11-12  |  20KB  |  488 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /* STR_DEMO.C                                                               */
  4. /*                                                                          */
  5. /* We have had several customers experience difficulty understanding the    */
  6. /* wn_gets function.  This is understandable, it is somewhat confusing.     */
  7. /* This demo will help you understand the features, including several new   */
  8. /* powerful features, and implement simpler forms to get basic items        */
  9. /* such as time, date, phone numbers, etc.  The modified wn_gets is fully   */
  10. /* compatible with the previous version so none of your code need change.   */
  11. /* However, a new function called wn_gets_ll (which wn_gets calls)          */
  12. /* has added the capability to uppercase the first char of each word,       */
  13. /* strip the mask completely, only strip the end, or not strip at all.      */
  14. /* It can also get input right-to-left, clear the entry on the first valid  */
  15. /* key, and return when the last character of the input is typed.           */
  16. /* Most importantly, it can allow the input of a string longer than the     */
  17. /* display width of the field and will scroll within this region auto-      */
  18. /* matically!  It can also display arrows to show the user that the string  */
  19. /* has data to the left or right of the current display field.              */
  20. /*                                                                          */
  21. /* Two newer capabilities of wn_gets_ll are the validation function hook,   */
  22. /* which can be called on each valid key pressed, and the gets hook, which  */
  23. /* is called on wn_gets_ll entry, exit, and for every key pressed.  We will */
  24. /* use the validation hook to show how you can do simple date validation,   */
  25. /* and we will use the gets hook to print out the text, mask and template   */
  26. /* strings for each key pressed, as well as make the F1 key perform a clear */
  27. /* on the input.                                                            */
  28. /*                                                                          */
  29. /* Note:  Compile this file with the warning "parameter 'ident' is never    */
  30. /*        used" turned off, as we don't have to actually use each parameter */
  31. /*        included in the validation and gets hook functions.               */
  32. /*                                                                          */
  33. /*------------------------- flags for wn_gets_ll ---------------------------*/
  34. /*                                                                          */
  35. /* G_STRIP          strips the entire mask from the string.                 */
  36. /*                * 12/04/91 = 120491, (432)-555-3421 = 4325553421                    */
  37. /*                                                                          */
  38. /* G_STRIP_END      strips the end of the string only only.                            */
  39. /*                * John Doe______ = John Doe                                                    */
  40. /*                                                                          */
  41. /* G_UP_FST_CHAR    converts the first letter of each word to uppercase.    */
  42. /*                * this is a test = This Is A Test                         */
  43. /*                                                                          */
  44. /* G_ARROW          displays left and right arrows if display width is less */
  45. /*                  than field width. NOTE: This requires an additional     */
  46. /*                  screen/window space before and after the field.         */
  47. /*                                                                          */
  48. /* G_RIGHT_TO_LEFT  gets input from the right side of the string, scooting  */
  49. /*                  characters over to the left for each valid press.       */
  50. /*                                                                          */
  51. /* G_CLEAR_ON_FIRST clears out the entry when the first valid key is        */
  52. /*                  pressed.  This saves a CTRL-Y keystroke to clear the    */
  53. /*                  entry.                                                  */
  54. /*                                                                          */
  55. /* G_EXIT_ON_FILL   causes the routine to exit whenever the last valid key  */
  56. /*                  is pressed.  This saves an extra <Enter> press.         */
  57. /*                                                                          */
  58. /*--------------------------------------------------------------------------*/
  59. /*                                                                          */
  60. /* Understanding these few flags and looking at the below examples make     */
  61. /* a very complex input routine much more managable!                        */
  62. /*                                                                          */
  63. /****************************************************************************/
  64. #include <stdlib.h>
  65. #include "uw.h"
  66. #include "uw_globx.h"
  67. #include "uw_keys.h"
  68.  
  69.  
  70. /*-------------------------- a few global variables ------------------------*/
  71. WINDOW Main_wn;
  72. char name1[32],  name2[32],  name3[32],
  73.          phone1[16], phone2[16], phone3[16],
  74.          date1[16],  date2[16],  date3[16],
  75.          time1[16],  time2[16],  time3[16];
  76.  
  77.  
  78. /*-------------------------- just some prototypes --------------------------*/
  79. void msg_line( char *msg );
  80. int my_gets(char *s, int max_len, int disp_width, int flags, int clear, WINDOW *wnp);
  81. int my_get_phone(char *s, int disp_width, int flags, WINDOW *wnp);
  82. int my_get_date(char *s, int disp_width, int flags, int clear, WINDOW *wnp);
  83. int my_get_time(char *s, int disp_width, int flags, WINDOW *wnp);
  84. int date_vld(char *w, char *t, char *m, int pos, int max_pos, WINDOW *wnp );
  85. int time_vld(char *w, char *t, char *m, int pos, int max_pos, WINDOW *wnp );
  86. int super_hook( char *text, char *template, char *mask, int pos,
  87.                                 int max_pos, int p_flag, EVENT *eventp, WINDOW *wnp );
  88.  
  89.  
  90. /*********/
  91. /* ~main */
  92. /*       ********************************************************************/
  93. /****************************************************************************/
  94. int main()
  95. {
  96.     int r;
  97.     WINDOW *wnp;
  98.  
  99.     init_video(80, 25);
  100.     init_clock(0x3333);
  101.     wnp = &Main_wn;
  102.     wn_create( 0, 0, V_cols-1, V_rows-1, DBL_BDR, WN_NORMAL, wnp );
  103.     wn_color( WHITE, BLUE, wnp );
  104.     wn_bdr_color( WHITE, BLUE, wnp );
  105.     wn_set(wnp);
  106.     wnp->inside = OFF;
  107.     wn_plst(CENTERED, 0, "<<< EnQue's String Entry Demonstration >>>", wnp);
  108.     wn_color(LIGHTGRAY, BLUE, wnp);
  109.     wn_plst(CENTERED, 1, "F1 is translated to CTRL-Y and parameters displayed by the new gets hook.", wnp);
  110.  
  111.     /* NOTE:
  112.          When we use set_gets_hook or set_validation_func, we can just call the
  113.          name of the function when using good old "C", but we have to do the
  114.          wild-looking function pointer cast when we use the C++ compiler.
  115.          If you rename this "C" file to a "CPP" file and compile under Turbo or
  116.          Borland C++ you will get a "Type mismatch in parameter func_ptr"
  117.          compiler error (not warning) if you just use the function name without
  118.          the cast!
  119.     */
  120.  
  121. #ifdef __cplusplus
  122.     set_gets_hook( (int (*)(...)) super_hook );
  123. #else
  124.     set_gets_hook( super_hook );
  125. #endif
  126.  
  127.     wn_color( WHITE, BLUE, wnp );
  128.     wnp->inside = ON;
  129.  
  130. /*---------- display full width and convert first char to uppercase --------*/
  131.     r = 2;
  132.     msg_line("Entry with first letters capped and no strip");
  133.     wn_plst(  2, r, "Enter your name  : ", wnp );
  134.     my_gets(name1, 22, 22, G_UP_FST_CHAR, 1, wnp);
  135.     wn_plst( 50, r, name1, wnp );
  136.  
  137. /*----------- display full width with strip to end and exit on fill --------*/
  138.     r++;
  139.     msg_line("Entry with strip to end and exit on fill");
  140.     wn_plst(  2, r, "Enter your name  : ", wnp );
  141.     my_gets(name2, 22, 22, G_STRIP_END | G_EXIT_ON_FILL, 1, wnp);
  142.     wn_plst( 50, r, name2, wnp );
  143.  
  144. /*---------- display only 6 characters, strip the entire mask, -------------*/
  145. /*---------- convert first char, and display arrows...         -------------*/
  146.     r++;
  147.     msg_line("Entry with first letters capped, strip, scrolling, and arrow chars